package com.easycoding.ums.security.captcha;

import java.awt.Color;
import java.awt.Font;

import com.octo.captcha.component.image.backgroundgenerator.BackgroundGenerator;
import com.octo.captcha.component.image.backgroundgenerator.UniColorBackgroundGenerator;
import com.octo.captcha.component.image.color.RandomRangeColorGenerator;
import com.octo.captcha.component.image.fontgenerator.FontGenerator;
import com.octo.captcha.component.image.fontgenerator.RandomFontGenerator;
import com.octo.captcha.component.image.textpaster.RandomTextPaster;
import com.octo.captcha.component.image.textpaster.TextPaster;
import com.octo.captcha.component.image.wordtoimage.ComposedWordToImage;
import com.octo.captcha.component.image.wordtoimage.WordToImage;
import com.octo.captcha.component.word.wordgenerator.RandomWordGenerator;
import com.octo.captcha.component.word.wordgenerator.WordGenerator;
import com.octo.captcha.engine.image.ListImageCaptchaEngine;
import com.octo.captcha.image.gimpy.GimpyFactory;

public class MyImageCaptchaEngine extends ListImageCaptchaEngine {

	@Override
	protected void buildInitialFactories() {
		WordGenerator wgen = new RandomWordGenerator("ABCDEFGHJKLMNOPQRSTUVWXYZ23456789");   
        RandomRangeColorGenerator cgen = new RandomRangeColorGenerator(   
             new int[] {0, 100},   
             new int[] {0, 100},   
             new int[] {0, 100});   
        //文字显示4个数   
        //TextPaster textPaster = new RandomTextPaster(new Integer(4), new Integer(4), cgen, true);   
        TextPaster textPaster = new RandomTextPaster(new Integer(4), new Integer(4), cgen, false);
        //图片的大小   
        BackgroundGenerator backgroundGenerator = new UniColorBackgroundGenerator(new Integer(80), new Integer(25),Color.WHITE);   

        Font[] fontsList = new Font[] {   
            new Font("Arial Black", 0, 14)
         };   
         
        FontGenerator fontGenerator = new RandomFontGenerator(new Integer(14), new Integer(14), fontsList);   

         WordToImage wordToImage = new ComposedWordToImage(fontGenerator, backgroundGenerator, textPaster);   
         this.addFactory(new GimpyFactory(wgen, wordToImage));   
	}

}
